﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using iLangl.Model;
using iLangl.BusinessModel.Managers;
using iLangl.Transport;


namespace iLangl.BusinessModel.Transport
{
	public class WCFConsumerRouter : ITransport
	{
		public void SendRequest(UploadRequest request)
		{
			PluginLicense pl = PluginManager.Instance.GetLicense(request.LicenseKey);
			WCFConsumer consumer = new WCFConsumer(pl.PushURL);
			consumer.SendRequest(request);
		}

		public UploadLightResponse SendRequestSync(UploadLightRequest request)
		{
			PluginLicense pl = PluginManager.Instance.GetLicense(request.LicenseKey);
			WCFConsumer consumer = new WCFConsumer(pl.PushURL);
			UploadLightResponse ulresponse = consumer.SendRequestSync(request);

			if (ulresponse.Responses.Length <= 0)
			{
				IError error = new Error(
			"The iLangl system is not able to get result of pusing data!",
			String.Format("For license key '{0}' push action by url='{1}' was failed. The reasons unknown!", pl.ID, pl.PushURL),
			eSeverity.Medium);
				//TODO: Generate Alert
			}

			return ulresponse;

		}
	}
}
